/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mx.saco.util;

import com.scitum.encryptor.util.password.StrongPasswordEncryptor;



/**
 *
 * @author LY005213
 */
public class EncriptaPassword {

    public static String reemplazaCaracteres(String cadena) {

        return quitaEspacios(reemplazaEspeciales(cadena));
    }

    public static String reemplazaCaracteres2(String cadena) {

        return quitaEspacios(reemplazaEspeciales2(cadena));
    }

    public static String reemplazaEspeciales(String cadena) {
        String caracteres = "-.!\"$%&@/())=?¡*¨}{¥[]´+_.;|°,¿¡0123456789ÓóòÒÑ#";
        cadena = cadena.toUpperCase();
        char[] caracEsp = caracteres.toCharArray();
        for (int i = 0; i < caracEsp.length; i++) {
            cadena = cadena.replace(caracEsp[i], ' ');
        }
        return cadena;
    }

    public static String reemplazaEspeciales2(String cadena) {
        String caracteres = "-.())=¨}{[]´+_.|°,¡0123456789";
        cadena = cadena.toUpperCase();
        char[] caracEsp = caracteres.toCharArray();
        for (int i = 0; i < caracEsp.length; i++) {
            cadena = cadena.replace(caracEsp[i], ' ');
        }
        // cadena = cadena.replace('�', 'N');
        cadena = cadena.replace('#', 'N');
        // cadena = cadena.replace('�', 'N');
        //cadena = cadena.replace('�', 'N');
        //cadena = cadena.replace('�', 'N');
        //cadena = cadena.replace('�', 'N');
        //cadena = cadena.replace('�', 'N');
        cadena = cadena.replace('?', 'N');
        //cadena = cadena.replace('�', 'N');
        cadena = cadena.replace('!', 'N');
        cadena = cadena.replace('/', 'N');
        cadena = cadena.replace('\\', 'N');
        //cadena = cadena.replace('�', 'N');
        cadena = cadena.replace('@', 'N');
        cadena = cadena.replace('&', 'N');
        cadena = cadena.replace('*', 'N');
        cadena = cadena.replace('$', 'N');
        cadena = cadena.replace('%', 'N');
        cadena = cadena.replace('^', 'N');
        cadena = cadena.replace(';', 'N');

        return cadena;
    }

    public static String quitaEspacios(String cadena) {
        String nuevaCadena = "";
        for (int i = 0; i < cadena.length(); i++) {
            if (cadena.charAt(i) != ' ') {
                nuevaCadena += cadena.charAt(i);
            }
        }
        return nuevaCadena;
    }

    public static boolean verificaCadenaEncriptada(String cadena,
            String encriptada) {
        StrongPasswordEncryptor passwordEncryptor = new StrongPasswordEncryptor();
        return passwordEncryptor.checkPassword(cadena, encriptada);
    }

    public static String encriptaPassword(String cadena) {
        StrongPasswordEncryptor passwordEncryptor = new StrongPasswordEncryptor();
        String encryptedPassword= passwordEncryptor.encryptPassword(cadena);
        return encryptedPassword;
    }

    public static void main(String[] args) {
        String cad = encriptaPassword("manage");
        System.out.println("pass: " + cad);
        System.out.println(verificaCadenaEncriptada("manage", cad));
    }

}
